package com.steakliu.event.register;

import com.steakliu.event.register.domain.NoticeMessageDTO;
import com.steakliu.event.register.domain.UserRegisterDTO;
import com.steakliu.event.register.event.MessageEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author 刘牌
 * @Title:
 * @date 2022-06-2323:25
 */
@Component
@Slf4j
public class UserService {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @Async
    public void registerUser(UserRegisterDTO userRegisterDTO){
        //保存用户
        saveUser(userRegisterDTO);
        //短信通知
        NoticeMessageDTO noticeMessageDTO = new NoticeMessageDTO().setTel("13657746155").setEmail("2319492349@qq.com");
        applicationEventPublisher.publishEvent(new MessageEvent(noticeMessageDTO));
    }

    public boolean saveUser(UserRegisterDTO userRegisterDTO){
        log.info("保存注册用户");
        return true;
    }
}
